package com.sy.service.impl;

import com.sy.entity.Commit;
import com.sy.service.CommitService;
import com.sy.vo.CommitAdd;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Objects;

@Service
public class CommitServiceImpl extends BaseServiceImpl implements CommitService {
    @Override
    public void addCommitByCommitAdd(CommitAdd commitAdd) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        String nowTime = df.format(new Date());
        System.out.println();// new Date()为获取当前系统时间
        if(commitAdd.getType()==1){
            Integer countByTrainerId = driSchoolMapper.getCountByDriSchoolId(commitAdd.getId());
            boolean b = driSchoolMapper.updateCountByDriSchoolId(countByTrainerId + 1,commitAdd.getId());
        }else if (commitAdd.getType()==2){
            Integer countByTrainerId = trainerMapper.getCountByTrainerId(commitAdd.getId());
            boolean b = trainerMapper.updateTrainer(countByTrainerId + 1,commitAdd.getId());
        } else if(commitAdd.getType()==3){
            Integer countByTrainerId = partnerMapper.getCountByPartnerId(commitAdd.getId());
            boolean b = partnerMapper.updateCountByPartnerId(countByTrainerId + 1,commitAdd.getId());
        }
        boolean b = commitMapper.addCommitByCommitAdd(commitAdd.getId(), commitAdd.getType(), commitAdd.getUserName(), commitAdd.getTextarea(), nowTime, commitAdd.getValue1(), commitAdd.getValue2(), commitAdd.getValue3(), commitAdd.getValue4());
//        System.out.println(b);
    }

    @Override
    public List<Commit> getCommitList(Integer id, Integer type) {
        if (Objects.isNull(id)) {
            buildError(HttpStatus.NOT_FOUND, "评论对象id不能为空");
        }
        if (Objects.isNull(type)) {
            buildError(HttpStatus.NOT_FOUND, "评论对象类型不能为空");
        }
        return commitMapper.getCommitListByDrId(id, type);
    }
}
